import java.io.File;

/**
 * User: rmikhaylenko mirusnet@gmail.com
 * Date: 12/08/13
 * Time: 13:43
 */
public class CommonIO {

    public static void checkFileAvailability(String filename) {
        File file = new File(filename);
        if (!file.exists()) {
            System.out.println("*** Unable to open a file " + filename);
            System.exit(1);
        }
    }

    public static void checkDirAvailability(String dirname) {
        File dir = new File(dirname);
        if (!dir.exists()) {
            System.out.println("*** Unable to open a directory " + dirname);
            System.exit(1);
        }

        if (!dir.isDirectory()) {
            System.out.println("*** Unable to enter to the playlist dir " + dirname);
            System.exit(1);
        }
    }

    public static String getFileNameWithOutExtention(String fullFilePath) {
        checkFileAvailability(fullFilePath);
        File file = new File(fullFilePath);
        String[] fields = file.getName().split("[.]+");
        return fields[0];
    }

}
